package com.shandao.shangxiu.ui;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;

import com.shandao.shangxiu.R;
import com.shandao.shangxiu.base.BaseActivity;
import com.shandao.shangxiu.util.UIHelper;
import com.shandao.shangxiu.widget.CleanableEditText;


/**
 * 设置登录密码页面
 * @author king
 */
public class ChangeLoginPasswordActivity extends BaseActivity {

    private CleanableEditText et_new_password;// 新登录密码输入
    private CleanableEditText et_new_password_confirm;// 新登录密码确认输入
    private Button btn_submit;// 下一步按钮

    private String password;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_change_login_password;
    }

    @Override
    public void initView() {
        et_new_password = (CleanableEditText) findViewById(R.id.et_new_password);
        et_new_password_confirm = (CleanableEditText) findViewById(R.id.et_new_password_confirm);
        btn_submit = (Button) findViewById(R.id.btn_submit);

        btn_submit.setOnClickListener(this);
    }

    @Override
    public void initData() {
        setToolbarTitle("设置新密码");
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.btn_submit){
            submit();
        }

    }


    /**
     * 设置登录密码
     */
    private void submit() {
        if (!isPrepareForSubmit()){
            return;
        }
        showWaitDialog(R.string.submit);
//        Api.checkPassWord(TAG, password, "1", new VolleyInterface<ResponseBase>() {
//
//			@Override
//			public void onSuccess(ResponseBase result) {
//				hideWaitDialog();
//                UIHelper.showSetupGesturePasswordActivity(ChangeLoginPasswordActivity.this);
//                finish();
//			}
//
//			@Override
//			public void onFailed(String errorrMsg) {
//				hideWaitDialog();
//				showToast(errorrMsg);
//			}
//		});
        UIHelper.showLoginActivity(ChangeLoginPasswordActivity.this);
        finish();
    }

    private boolean isPrepareForSubmit() {
        isPrepareForNet();
        password = et_new_password.getText().toString().trim();
        if(TextUtils.isEmpty(password)){
        	showToast(getString(R.string.password_error));
        	return false;
        }
        String confirm = et_new_password_confirm.getText().toString().trim();
        if(TextUtils.isEmpty(confirm)){
            showToast(getString(R.string.password_error));
            return false;
        }
        if(!password.equals(confirm)){
            showToast(getString(R.string.password_confirm_error));
            return false;
        }
        return true;
    }
}
